package com.c.ctgproject.wiget.dialog

import android.os.Bundle
import android.view.View
import android.widget.RelativeLayout
import androidx.lifecycle.ViewModelProvider
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseDialogFragment
import com.c.ctgproject.utils.*
import kotlinx.android.synthetic.main.item_input_name_dialog.*
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File
import java.lang.StringBuilder

/**
 * 作者:LiBW
 * 创建日期: 2021/7/6
 * 描述:审批签字 Dialog
 */
class CheckInputNameDialog( private val loading: LoadingDialog,private val listener:CheckInputNameDialogCallback) : BaseDialogFragment() {
    override fun getLayout() = R.layout.item_input_name_dialog

    override fun viewIsCreated(view: View, savedInstanceState: Bundle?) {
        mInitSignatureBTN.setOnClickListener {
            dismiss()
        }
        //重置
        mResetBTN.setOnClickListener {
            mSignatureView.initPaint()
        }
        //确认
        mConfirmBTN.setOnClickListener {
            requireActivity().upDataFile(loading,arrayListOf(File(mSignatureView.saveImage()))) {
                if (it != null && it.isNotEmpty()) {
                    listener.onImageGet(it[0].fileUrl.handlerNull())
                } else {
                    showToast("图片上传异常请稍后再试")
                }
            }
        }
    }




    override fun onStart() {
        super.onStart()
        dialog!!.window!!.setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT)
    }

    interface CheckInputNameDialogCallback{
        fun onImageGet(url:String)
    }
}